package com.songcan.oauth.other;

import com.songcan.common.vo.UserDetailsNew;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.SpringSecurityCoreVersion;

import java.util.Collection;
import java.util.List;

public class CoreLoginAuthenticationToken extends AbstractAuthenticationToken {


    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;

    private final Object principal;
    private String type;
    private Boolean bindMobile;


    public CoreLoginAuthenticationToken(String type, Boolean bindMobile, UserDetailsNew userDetailsNew) {
        super(null);
        this.principal = userDetailsNew;
        this.type = type;
        setAuthenticated(false);
        this.bindMobile = bindMobile;
    }

    public CoreLoginAuthenticationToken(UserDetailsNew userDetailsNew, String type) {
        super(userDetailsNew.getAuthorities());
        this.principal = userDetailsNew;
        super.setAuthenticated(true);
        this.type = type;

    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }


    public String getType() {
        return this.type;
    }



    public Boolean getBindMobile(){
        return this.bindMobile;
    }
    public void setBindMobile(Boolean bindMobile) {
        this.bindMobile = bindMobile;
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        if (isAuthenticated) {
            throw new IllegalArgumentException(
                    "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
        }
        super.setAuthenticated(false);
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
    }
}
